<?php session_start(); ?>
<?php 
	header ( "Content-type:text/html;charset=utf-8" );
	require_once('../php/db/properties.inc.php');
	@$userInfo = $_SESSION["userInfo"];
	if(!$userInfo){
		header("Location: login.html");
		exit;
	}
	$jsonObject = json_decode($userInfo);
	@$blogId = $_GET["blogId"];
	$userId = "";
	$content = "";
	$title = "";
	$blogIds = "";
	if(!empty($blogId)){
		$conn = new mysqli($url, $user, $pwd, $dbname, $port);
		$conn -> set_charset("utf8");
		$sql = "SELECT b.userId,b.title,t.content FROM bolggerTitle b,bolggerContent t  WHERE b.id=t.titleId AND  b.id=".$blogId;
		
		if(!$conn->connect_error){
			$results = $conn->query($sql);
			while ($row = $results->fetch_object()) {
				$userId = $row->userId; 
				$userIds = $jsonObject->id;
				if($userId==$userIds){
					$content = $row->content;
					$title = $row->title;
					$blogIds = $blogId;
				}
				     	
			}
			$results->close();
		}
		$conn -> close();
	}
	
?>
<!DOCTYPE html>
<html >
 <head>
  <title>淡炒番茄 </title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  <meta name="description" content="不知道为什么就是想写个网站玩儿，但技术不行将就用吧!"/>
  <meta name="viewport"  content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"/>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="keywords" content=""/>
  <meta name="robots" content="index,follow" />
  <meta name="full-screen" content="yes">
  <meta name="x5-fullscreen" content="true">
  <link href="../css/common.css" rel="stylesheet"/>
  <link href="../css/content.css" rel="stylesheet"/>
  <script type="text/javascript" src=""></script>
  <script type="text/javascript" src="../js/jquery-3.1.1.min.js"></script>
  <script type="text/javascript" src="../js/smallarAlert.js"></script>
  <script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
  <script type="text/javascript" src="../ueditor/ueditor.all.js"></script>
  <script type="text/javascript" src="../ueditor/ueditor.parse.js"></script>
  <script type="text/javascript">
      var ua = navigator.userAgent;
      window.onload = function(){
          if(ua.match(/(iPhone|iPod|Android|ios)/i)){
              $(".dfb").css("width","100%");
              $(".contnrhe").css("width","100%");
              $(".contnrr").css("width","100%");
          }
      };
  </script>
</head>
<body class="dfb">
	<div class="bodco bodyd" >
		<div class="contbt">
			<ul>
				<li><a href="list.php?type=2" class="fonts1 font3 remFlo clicks1">小技术</a></li>
				<li><p  class="fonts font1">|</p></li>
				<li><a href="list.php?type=1" class="fonts1 font3 remFlo clicks1">小信息</a></li>
			</ul>
		</div>
		<div class="contnr">
			<div class="contnrhe">
				<div class="contnrheim">
				<?php 
					$headValue = "";
					if($jsonObject -> head){
						echo "<img class='contnrheimm'  src='../".($jsonObject->head)."'>";
					} else{
						echo "<img class='contnrheimm'  src='../img/he.png'>";
					}
				?>
				</div>
				<div class="fonts font3 contnrhecon">
					<?php echo $jsonObject -> userName ?>
				</div>
				<div class="fonts font2 contnrhecon contnrhetext">
					地址：<?php echo ($jsonObject -> provinces) ? (($jsonObject -> provinces)."-".($jsonObject -> city) ) : "未知" ?>
				</div>
				<div class="contnrhecon contnrhetext">
					<a href='editUserInfo.php' class="fonts font2 clicks1 remFlo" >修改信息</a>
				</div>
			</div>
			<div class="contnrr">
				<div class="fonts font1 contnrrbt" >
					<span style="color:red;">*</span>标题(最多25个字)&nbsp;文章分类：
					<select style="height: 2em;width: 6em;margin-bottom: 2px;" id="contType">
						<option value="1" >小信息</option>
						<option value="2">小技术</option>
					</select> <br>
					<input id="heading" style="height: 30px;width: 98%;font-size: 0.8em;margin-top:0.5em;" type="text"/>
				</div>
				<div class="contnrrbotedit" >
					<form id="contents" accept-charset="utf-8" action="../php/action/content.php" method="post">
						<input id="headingt" name="headingt" style="display:none;">
						<input id="types" name="types" style="display:none;">
						<input id="blogId" name="blogId" style="display:none;">
						<div class="contnrrbotedits">
							<script id="container" name="content" type="text/plain"></script>
						</div>
						<div class="contnrrbotconmetj" id="sumbitForm" onclick="saveValue();">
							提交
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<div class="bodco bodcohrs" ><hr class="bodyh"/></div> 
 	<div class="bodco bodyf">
 		 <p class='fonts font2'> @2016-2017 <a href="../index.php" class='fonts font2 ' style="text-decoration: none;" >淡炒番茄</a> （http://www.dancfq.top/)  备案号:蜀ICP备16034800号 </p>
 	</div>
 	
 	<script type="text/javascript">

 		var title = "<?php echo ((!empty($title)) ? $title:null) ?>";
 		var blogId = "<?php echo $blogIds?>";
 		var content = '<?php echo $content?>';
 		
 		var ue = UE.getEditor('container',{initialFrameHeight:300, maximumWords:1000});//初始化高度
 			
 		if(blogId){
 			 $("#heading").val(title);
 			 $("#blogId").val(blogId);
 			 ue.ready(function(){
				 ue.setContent(content);
			})
 			
 		}
 		
 		function saveValue(){
 			var html = ue.getContent();
 			var txt = ue.getContentTxt();
 			var bts = $("#heading").val();
 			var type = $("#contType").val();
 			
 			if(!bts){
 				alerts("少年，你的标题呢！");
 				return false;
 			}
 			
 			if(bts.length>20){
 				alerts("少年，你的标题太长了！");
 				return false;
 			}
 			
 			if(txt.length==0){
 				alerts("吐槽你也不干！写点内容啊！");
 				return false;
 			}
 			if(txt.length>1000){
 				alerts("字太多啦！少点少点！");
 				return false;
 			}
 			$("#headingt").val(bts);
 			$("#types").val(type);
 			$("#contents").submit();
 			$("#sumbitForm").unbind("click");
 		}
 		
 		
 		function alerts(message){
  			$.MsgBox({type:"alert",speed:200,title:"登录",msg:message,opacity:'0.5',callback:function(){}});
  		}
 	</script>
</body>
</html>